package com.bw.controller;

import com.bw.domain.TPerson;
import com.bw.service.TPersonService;
import com.bw.utils.common.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author bobo棒
 * @date 2024年01月02日 11:08
 */

@RequestMapping("person")
@RestController
public class PersonController {
    @Autowired
    TPersonService tPersonService;

    @RequestMapping("list")
    public Result List(@RequestBody  TPerson tPerson, @RequestParam(defaultValue = "1") Integer pageNum){

        PageHelper.startPage(pageNum,3);
         List<TPerson> list= tPersonService.list2(tPerson);
         return Result.success(new PageInfo<>(list));
    }

    @RequestMapping("add")
    public Result add(@RequestBody  TPerson tPerson ){
        tPerson.setCreated(new Date());
        boolean b = tPersonService.save(tPerson);
        return b?Result.success():Result.fail();
    }

    @RequestMapping("update")
    public Result update(@RequestBody  TPerson tPerson ){

        boolean b = tPersonService.updateById(tPerson);
        return b?Result.success():Result.fail();
    }
}
